package dexter.core.host;

import java.io.IOException;

import dexter.net.Consumer;
import dexter.net.msg.common.RequestListener;

import dexter.aware.Sensor;

public class Host {

	public static final int PORT = 54324;
	private Consumer consumer;

	public Host(int port) {
		consumer = new Consumer(port);
	}
	
	public void start(){
		  
		  RequestListener nlistener = new HostListener();
		  try {
			consumer.receive(nlistener);
			System.out.println("Node: Waiting for creation requests");
		} catch (IOException e) {
			e.printStackTrace();
		}
		 
	}
	
	public static void main(String[] args) {
		
		System.out.println("NODE INIT");
		
		String HOST = "localhost";
		int nodePort = PORT;
		
		if (args.length>1)  HOST = args[0]; 
		if (args.length>2)	nodePort = Integer.parseInt(args[1]); 
	
		Host node = new Host(nodePort);
		System.out.println("Node: Opening port "+nodePort);
		node.start();
		
		//HostAddress host = new HostAddress(HOST,nodePort);
		Sensor sensor = new Sensor();
		sensor.start();
		System.out.println("SENSOR END");
		
	}
}
